// pages/home/partner/year/year.js
import { getHhrIncomInfo } from '../../../../api/income'
 
const showCount = 20;
let currentPage = 1;
let totalPage = 1;
let loading = false;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    incomes: []
  },
  onShow: function (options) {
    currentPage = 1;
    totalPage = 1;
    this.setData({
      incomes: []
    })
      this.getHhrIncomInfo()
  },

  getHhrIncomInfo(){
    if(loading){
      return ;
    }
    loading = true
    getHhrIncomInfo({
      showCount,
      currentPage,
    })
    .then(res => {
      
      loading=false

      totalPage = res.data.totalPage
      let incomes = res?.data?.list || []
      
      if(incomes.length> 0){
        let prelist = this.data.incomes
        this.setData({
          incomes: prelist.concat(incomes)
        })
        currentPage++
      }
    })
    .catch(err => {
      
      loading=false
    })


  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (currentPage > totalPage) {

      wx.showToast({
        title: '已经到底了', icon: 'none'
      })
      return;
    }

    this.getHhrIncomInfo();
  },

})